package com.gable.report.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * Created by gable on 2018/7/3.
 */
@Component
@EnableScheduling
public class ScheduledTasks {

    @Autowired
    RedisTemplate redisTemplate;

    private static final Logger logger = LoggerFactory.getLogger(ScheduledTasks.class);

    /**
     * 清空redis缓存
     */
    @Scheduled(cron = "0 59 23 * * ?")
    public void cleanRedis() {
        if(RedisUtil.isOn){
            redisTemplate.getConnectionFactory().getConnection().flushDb();
            logger.info("----------------清空redis--------------------------------");
        }
    }
}
